﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;
using Whir.Common.Resource;

public partial class Whir_System_Sys_Top : System.Web.UI.UserControl
{
    protected string key = "";
    protected bool bValue;//是否超级管理员

    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断
        key = Whir.Common.Settings.GetString("AdminCacheKey");
        string value = StringHelper.GetCookie(key);
        bValue = (RoleHelper.AdminCache.typeID == 1) ? true : false;//是否超级管理员

        if (!IsPostBack)
        {
            string adminName = RoleHelper.AdminCache.adminName;
            this.lbAdminName.Text = adminName;
            this.lbWelCome.Text = ResourceManager.GetString("welcome");
            this.lblogout.Text = ResourceManager.GetString("logout");
            this.lbnLogout.Attributes["onclick"] = "return confirm('" + ResourceManager.GetString("logoutmsg") + "')";
            this.lbleditpass.Text = ResourceManager.GetString("editpass");

            InitPageLanguage();

            //显示菜单控制
            if (!bValue)
            {
                //不是超级管理员，只显示网站管理和帮助
                tab1.Visible = true;
                tab4.Visible = true;
                tab2.Visible = false;
                tab3.Visible = false;
            }
        }
    }

    /// <summary>
    /// 初始化页面语言
    /// </summary>
    private void InitPageLanguage()
    {
        Label1.Text = ResourceManager.GetString("website");
        Label2.Text = ResourceManager.GetString("system");
        Label3.Text = ResourceManager.GetString("tool");
        Label4.Text = ResourceManager.GetString("help");
    }

    protected void lbnLogout_Click(object sender, EventArgs e)
    {
        Whir.Log.Model.Whir_OperateLog model = new Whir.Log.Model.Whir_OperateLog();
        model.title = "退出";
        model.operateType = 6;      //退出
        model.operateResult = true;
        model.operateDesc = "退出";

        Whir.Log.OperateLog.Add(model);

        HttpContext.Current.Response.Cookies.Remove(key);

        Page.ClientScript.RegisterStartupScript(typeof(Page), "", "<script>window.open('../login.aspx','_top');</script>");
        return;
    }

}
